<?
/**
 * Copyright 2007 Melange.
 *
 * This file is part of PHP-MELANGE.
 *
 * PHP-MELANGE is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * PHP-MELANGE is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PHP-MELANGE; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @category    Melange
 * @package     php-melange
 * @subpackage  cms
 * @copyright   Copyright (c) 2007 Jeroen Simons. All rights reserved
 * @author      Jeroen Simons <jeroen@melange.nl>
 * @link        http://www.melange.nl/
 *
 */

require_once("cms/core/helper/bean/Abstract.php");
require_once("cms/menu/om/MenuPeer.php");
require_once("cms/menu/om/MenuItemPeer.php");

class PHP_CMS_View_Helper_Menus extends AbstractList {

    public function menus($listForm=null) {

        if($this->isInit) return $this;

        parent::init($listForm);

//        $this->criteria->add(
//            MenuItemPeer::MENU_ID, 0, Criteria::GREATER_THAN);

        $this->criteria->addJoin(
            MenuPeer::MENU_ID, MenuItemPeer::MENU_ID, Criteria::LEFT_JOIN);

        $this->criteria->addAsColumn(
            'count', 'COUNT(' . MenuItemPeer::MENU_ITEM_ID . ')');

        $this->criteria->addGroupByColumn(
            MenuPeer::MENU_ID);

        $this->criteria->setDistinct();

        return $this;
    }


    /**
     * Define the propel peer we are going to use to list
     * items.
     */
    public static function getPeer() {
        return new MenuPeer();
    }


    /**
     * Set the searchable fields for this list page.
     */
    public static function getFields() {
        return array(
            MenuPeer::NAME,
            MenuPeer::INSERT_DATE,
            MenuPeer::MODIFIED_DATE
        );
    }
}
?>